<!-- 企业用户分成信息统计 -->
<template>
  <div>
    <HomeCard title="成果数量统计" isTimer headIcon="img_10" @checkedTimer="checkedTimer">
      <template v-slot:content>
        <div class="business-info-right">
          <HomeEcharts ref="EchartsRef" :echartsOption="echartsOption" />
        </div>
      </template>
    </HomeCard>
  </div>
</template>

<script type="text/javascript">
import HomeCard from "@/pages/components/homeCard/index.vue";
import HomeEcharts from "@/pages/components/homeEcharts/index.vue";
import { companyEarningsDateStatistics } from "@/api/home.js";

export default {
  name: "todo-page",
  components: {
    HomeCard,
    HomeEcharts,
  },
  data () {
    return {
      echartsOption: {
        backgroundColor: "#fff",
        legend: {
          right: 0,
          itemWidth: 20,
          itemHeight: 4,
          // itemGap: 10,
          show: true,
          data: [
            {
              name: "数量",
              icon: "rect",
            },
            {
              name: "金额",
              icon: "rect",
            },
          ],
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            lineStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(0, 255, 233,0)",
                  },
                  {
                    offset: 0.5,
                    color: "rgba(255, 255, 255,1)",
                  },
                  {
                    offset: 1,
                    color: "rgba(0, 255, 233,0)",
                  },
                ],
                global: false,
              },
            },
          },
        },
        grid: {
          top: "15%",
          left: "10%",
          right: "5%",
          bottom: "15%",
          // containLabel: true
        },
        xAxis: [
          {
            type: "category",
            axisLine: {
              show: false,
              color: "#A582EA",
            },

            axisLabel: {
              color: "#A582EA",
              width: 100,
              margin: 20,
            },
            data: []
          },
        ],

        yAxis: [
          {
            type: "value",
            min: 0,
            // max: 140,
            splitNumber: 4,
            splitLine: {
              show: true,
              lineStyle: {
                color: "#00BFF3",
                opacity: 0.23,
              },
            },
            axisLine: {
              show: false,
            },
            axisLabel: {
              show: true,
              margin: 20,
              textStyle: {
                color: "#333",
              },
            },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [
          {
            name: "数量",
            type: "line",
            showAllSymbol: true,
            symbol: "circle",
            symbolSize: 10,
            lineStyle: {
              normal: {
                color: "#A582EA",
              },
            },
            label: {
              show: true,
              position: "top",
              textStyle: {
                color: "#A582EA",
              },
            },
            itemStyle: {
              color: "#A582EA",
              borderColor: "#fff",
              borderWidth: 2,
            },

            data: []
          },
          {
            name: "金额",
            type: "line",
            showAllSymbol: true,
            symbol: "circle",
            symbolSize: 10,
            lineStyle: {
              normal: {
                color: "#2CABE3",
              },
            },
            label: {
              show: true,
              position: "top",
              textStyle: {
                color: "#2CABE3",
              },
            },
            itemStyle: {
              color: "#2CABE3",
              borderColor: "#fff",
              borderWidth: 2,
            },
            data: []
          },
        ],
      },
      dateType: 'Day',
      orgId: ''
    };
  },
  mounted () {
    this.init()
  },
  methods: {
    async init () {
      const request = {
        dateType: this.dateType,
        orgId: this.orgId
      }
      const { countList, moneyList } = await companyEarningsDateStatistics(request)

      this.echartsOption.xAxis[0].data = countList.map(it => it.dateStr)
      this.echartsOption.series[0].data = countList.map(it => it.count)
      this.echartsOption.series[1].data = moneyList.map(it => it.money)

      this.$refs.EchartsRef.handleSetVisitChart();

    },
    checkedTimer (item) {
      this.dateType = item === '年' ? 'Year' : item === '月' ? 'Month' : 'Day'
      this.init()
    },

    setOrgId (orgId = '') {
      this.orgId = orgId
      this.init()
    }
  },

};
</script>

<style lang="less" scoped>
.business-info-right {
  margin: 18px 0 0 0;
  width: 100%;
  height: 310px;
  background: #f2f2f2;
}
</style>
